﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace Luna.Framework.Manifest {
	class BuilderManifestProcessor: IManifestProcessor {
		public bool isSupport(IConfigurationManifest manifest, Type hostManifestType) {
			return "builder".Equals(manifest.Name);
		}

		public bool process(IManifestManager manager, IConfigurationManifest manifest, object host, IAppContext context) {
			IAppContext hostContext = host.extractAppContext();
			if (hostContext == null)
				hostContext = context;
			Type builderType = manifest.Type;
			if (builderType != null && typeof(IObjectBuilder).IsAssignableFrom(builderType)) {
				IObjectBuilder builder = (IObjectBuilder)manifest.applyManifest(context, null);
				builder.buildObject(host, hostContext, manifest);
				return true;
			}
			return false;
		}
	}
}
